package edu.mis.modules.voucher;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;

import edu.mis.model.User;
import edu.mis.model.Voucher;

public class AuditController extends Controller {
	public void index() {
		render("audit.html");
	}

	/**
	 * 获取所有未审核的凭证
	 */
	public void list() {
		Integer page = getParaToInt("page");
		Integer rows = getParaToInt("rows");
		Page<Voucher> data = Voucher.dao.paginate2(page, rows);
		setAttr("rows", data.getList());
		setAttr("total", data.getTotalRow());
		renderJson();
	}

	/**
	 * 对凭证进行审核
	 */
	public void audit() throws Exception{
		Integer page = getParaToInt("page");
		Integer rows = getParaToInt("rows");
		String voucherId = getPara("voucherId");
		User user= getSessionAttr("loginUser");
		String auditor=user.getName();
		//修改审核人
		String sql="update voucher set auditor = '"+auditor+"' where voucherId="+voucherId;
		if (Db.update(sql)==1) {
			setAttr("success", true);
			setAttr("msg", "审核凭证成功!");
		} else {
			setAttr("success", false);
			setAttr("msg", "审核凭证失败!");
		}
		renderJson();
	}
}
